package com.akka.akkaacotr.config;

import com.akka.akkaacotr.servcie.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Iterator;

/**
 * ApplicationStartingEvent
 * <p>
 * ApplicationEnvironmentPreparedEvent
 * <p>
 * ApplicationPreparedEvent
 * <p>
 * ApplicationFailedEvent
 *
 * @author LHL
 * @date 2019/6/29
 */


public class InitConfig<T> implements ApplicationListener<ApplicationPreparedEvent> {
    @Autowired
    private BusinessService businessService;

    @Override
    public void onApplicationEvent(ApplicationPreparedEvent event) {
        System.out.println("-------->"+businessService);
    }

//    @Override
//    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
//        MutablePropertySources mps = event.getEnvironment().getPropertySources();
//        if (mps != null) {
//            Iterator<PropertySource<?>> iter = mps.iterator();
//            while (iter.hasNext()) {
//                PropertySource<?> ps = iter.next();
//                boolean b = ps.containsProperty("server.port");
//                if (b){
//                    System.out.println(ps.getName());
//                    System.out.println(ps.getClass());
//                }
//                System.out.println("=============>"+b);
//            }
//        }
//
//
//        System.out.println("========>bussiness:" + businessService);
//    }


//    @Override
//    public void onApplicationEvent(ApplicationStartingEvent event) {
//        SpringApplication springApplication = event.getSpringApplication();
//        springApplication.setBannerMode(Banner.Mode.OFF);
//    }
}
